package com.toman.ui.work.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.toman.Interfaces.NewBaseUrl;
import com.toman.JavaBean.SysCompanyEntity;
import com.toman.R;
import com.toman.Util.SPUtils;
import com.toman.Util.StringUtils;
import com.toman.Util.ToastUtil;
import com.toman.Util.ViewUtil;
import com.toman.toolbar.ToolBarActivity;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Request;
import okhttp3.Response;

public class CompanyInfActivity extends ToolBarActivity {

    @BindView(R.id.tv_company)
    TextView tvCompany;
    @BindView(R.id.tv_company_id)
    TextView tvCompanyId;
    @BindView(R.id.tv_company_xz)
    TextView tvCompanyXz;
    @BindView(R.id.tv_company_gm)
    TextView tvCompanyGm;
    @BindView(R.id.tv_company_qy)
    TextView tvCompanyQy;
    @BindView(R.id.cv_base)
    CardView cvBase;
    @BindView(R.id.tv_content1)
    TextView tvContent1;
    @BindView(R.id.tv_content2)
    TextView tvContent2;
    @BindView(R.id.tv_content3_title)
    TextView tvContent3Title;
    @BindView(R.id.tv_content3)
    TextView tvContent3;
    @BindView(R.id.tv_content4)
    TextView tvContent4;
    @BindView(R.id.tv_content5)
    TextView tvContent5;
    @BindView(R.id.cv_more)
    CardView cvMore;
    String id;
    @BindView(R.id.tv_content6)
    TextView tvContent6;
    @BindView(R.id.tv_content7)
    TextView tvContent7;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_company_inf);
        ButterKnife.bind(this);
        initToolBar("企业详情");
        initView();
        get();
    }

    private void initView() {
        id = getIntent().getStringExtra("id");

    }

    public void get() {


        String token = (String) SPUtils.get(getApplicationContext(), "token", "");
        OkHttpUtils
                .get(NewBaseUrl.company_info_get + id)
                .params("token", token)
                .params("id", id)
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "企业信息: " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");ViewUtil.lagout(code,getApplicationContext());
                        if (code == 0) {
                            SysCompanyEntity bean = (SysCompanyEntity) JSON.parseObject(jsonObj.getString("sysCompany"), SysCompanyEntity.class);
                            tvCompany.setText(bean.getCompanyName());
                            tvCompanyId.setText(bean.getCompanyCode());
                            if (!StringUtils.isEmpty(bean.getCompanyNature())) {
                                String items[] = new String[]{"国有企业", "集体企业", "联营企业", "股份合作制企业", "私营企业", "个体户", "合伙企业", "有限责任公司", "股份有限公司", "其它"};
                                try {
                                    tvCompanyXz.setText(items[Integer.parseInt(bean.getCompanyNature())]);
                                } catch (NumberFormatException e) {
                                    e.printStackTrace();
                                }
                            }

                            if (!StringUtils.isEmpty(bean.getCompanySize())) {
                                String items[] = new String[]{"0-99/人", "100-499/人", "500-2000/人", "2000人以上"};
                                tvCompanyGm.setText(items[Integer.parseInt(bean.getCompanySize())]);

                            }

                            if (bean.getIsSign() == 1) {
                                tvCompanyQy.setText("已签约");
                            } else {
                                tvCompanyQy.setText("未签约");
                            }
                            tvContent1.setText(bean.getCompanyContact());
                            tvContent2.setText(bean.getCompanyInformation());
                            tvContent3.setText(bean.getAreaName());
                            tvContent4.setText(bean.getLongitude());
                            tvContent5.setText(bean.getLatitude());
tvContent6.setText(bean.getCompanyShortName());
                            tvContent7.setText(bean.getAddress());


                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                    }
                });
    }
}
